<template>
    <div>
    </div>
</template>
<script lang="ts" setup>
import { getTokenUser } from "@/api/login";
const router = useRouter();
const route = useRoute();
const store = useStore();
const login = async () => {
    console.log(route.fullPath)
    // const 
    const token=route.fullPath.split('token=')[1].split('&redirectUrl=')[0]
    const toPath = decodeURIComponent(route.fullPath.split('token=')[1].split('&redirectUrl=')[1]);
    console.log(token,toPath)
    const rs = await getTokenUser({
        token:token
    })
    if (rs.code === 200) {
        store.commit("SETTOKEN", rs.payload.token);
        store.commit("SETUSERNAME", rs.payload.username);
        store.commit("SETALLPERMISSION", rs.payload.allPermission);
        store.commit("SETMERCHANTID", rs.payload.merchantId);
        store.commit("SETUERID", rs.payload.userId);
        store.commit("SETADMINTYPE", rs.payload.adminType);
        store.commit("SETUSERINFO", { insId: rs.payload.insId });
        // store.commit("SETSECRET", rs.payload.secret)
        // store.commit("SETSECRETENABLED", rs.payload.secretEnabled)
        if (toPath) {
            store.commit("SETCURRENTSERVICE", toPath.split("/")[1].toUpperCase());
            router.replace(toPath);
            store.commit("SETBOOKLIST", {
                path: toPath,
                service: store.state.user.currentService,
            });
        } 
    }
}
onMounted(()=>{
    login()
})
</script>